#pragma once
#include <iostream>
#include "Protocol.hpp"
class ServerCal
{
public:
    ServerCal() {}
    ~ServerCal() {}
    Response CalHelp(const Request &req)
    {
        Response resp;
        switch (req.op)
        {
        case '+':
            resp.res = req.x + req.y;
            break;
        case '-':
            resp.res = req.x - req.y;
            break;
        case '*':
            resp.res = req.x * req.y;
            break;
        case '/':
            if (req.y == 0)
            {
                resp.code = 1;
                break;
            }
            resp.res = req.x / req.y;
            break;
        case '%':
            if (req.y == 0)
            {
                resp.code = 1;
                break;
            }
            resp.res = req.x % req.y;
            break;
        default:
            resp.code = 1;
            break;
        }
        return resp;
    }
    std::string Cal(std::string &package)
    {
        std::string content;
        bool r = Decode(package, &content);
        if (!r) return "";
        Request req;
        r = req.Reserialize(content);
        if (!r) return "";
        Response resp = CalHelp(req);
        resp.Serialize(&content);
        content = Encode(content);
        return content;
    }

public:
};